import configparser
import os
import logging

logger = logging.getLogger(__name__)

def read_config(section, key, default=None):
    config = configparser.ConfigParser()
    config_file = "Config.ini"

    if not os.path.exists(config_file):
        logger.error(f"❌ 配置文件 {config_file} 不存在")
        return default

    try:
        config.read(config_file, encoding='utf-8')
        return config.get(section, key, fallback=default)
    except Exception as e:
        logger.error(f"❌ 读取配置失败 [{section}.{key}]：{str(e)}", exc_info=True)
        return default

def get_auth_api_base_url():
    return read_config("BaseApi", "base_url", "http://localhost")

def get_auth_api_third_url():
    return read_config("BaseApi", "third_url", "http://localhost")